Implement Clone for ToTitlecase iterator#4
Implement Clone for ToTitlecase iterator#4ginnyTheCat wants to merge 1 commit intoRustPython:masterfrom
Clone for ToTitlecase iterator#4Conversation
WalkthroughThe pull request adds Clone derivation to two iterator-related types in the crate: Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/lib.rs (1)
49-55: Good addition - enables cloning the iterator state.Deriving
CloneforCaseMappingIteris correct since all variants contain onlychartypes, which areCopy. This allows the iterator to be cloned at any point during iteration, creating an independent iterator at the same state.Consider adding a test to verify the
Clonefunctionality works as expected:#[test] fn test_to_titlecase_clone() { let mut iter1 = 'ß'.to_titlecase(); assert_eq!(iter1.next(), Some('S')); let mut iter2 = iter1.clone(); // Both iterators should independently produce the remaining character assert_eq!(iter1.next(), Some('s')); assert_eq!(iter2.next(), Some('s')); assert_eq!(iter1.next(), None); assert_eq!(iter2.next(), None); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/lib.rs(2 hunks)
🔇 Additional comments (1)
src/lib.rs (1)
92-93: Excellent - brings API parity with Rust standard library.Adding
Cloneto the publicToTitlecasestruct is a valuable improvement that aligns with Rust's standard library iterators (ToUppercaseandToLowercase). This allows users to clone the iterator and reuse the titlecase mapping without repeating the lookup operation.
This is just a blatant lie. |
This is done to allow iterating the results multiple times without needing to redo the lookup step. The std also provides this for
ToUppercaseandToLowercase.Summary by CodeRabbit